﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace WebApp
{

    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
        }
        protected void Session_Start(object sender, EventArgs e)
        {
        }
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            
        }
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
        }
        protected void Application_Error(object sender, EventArgs e)
        {
        }
        protected void Session_End(object sender, EventArgs e)
        {
        }
        protected void Application_End(object sender, EventArgs e)
        {
        }

        protected void Application_AcquireRequestState(object sender, EventArgs e)
        {

            //Aca ASP.NET esta puede verificar el estado de la session
            if (HttpContext.Current.Session != null)
            {
                DBAetosDataContext db = new DBAetosDataContext();
                UserQ _user = (UserQ)HttpContext.Current.Session["User" + Session.SessionID];
                if (_user != null)
                {
                    if (db.UserQs.Any(u => u.Id.Equals(_user.Id) && u.Role.Equals(0)))
                    {
                        Session["User" + Session.SessionID] = null;
                        Response.Redirect("~/Login.aspx?error=Su cuenta a sido cancelada, por favor contacte con sus asesores.");
                    }
                }
            }
        }

    }
}